/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nonequidistant.FEMSolver1D;

import Integration.IFunction1D;
import Integration.derivavty;

import java.util.ArrayList;
import nonequidistant.FEMShapeFunctions1D.FEMShapeFunction1D1Pow;

/**
 *
 * @author mark_o
 */
public class FEMResult implements IFunction1D{
    protected double[] res;
    ArrayList<FEMShapeFunction1D1Pow> FuncList;

    public FEMResult(double[] res, ArrayList<FEMShapeFunction1D1Pow> FuncList) {
        this.res = res;
        this.FuncList = FuncList;
    }

    public double calculate(double x) {
        double result = 0.0;
        FEMShapeFunction1D1Pow fEMShapeFunction1D1Pow = null;
        for (int i = 0; i < FuncList.size(); i++) {
            fEMShapeFunction1D1Pow = FuncList.get(i);
            result+= res[i]*fEMShapeFunction1D1Pow.calculate(x);
        }
        return result;
    }

    public double calculateDerivaty(double x) {
        double result = 0.0;
        FEMShapeFunction1D1Pow fEMShapeFunction1D1Pow = null;
        for (int i = 0; i < FuncList.size(); i++) {
            fEMShapeFunction1D1Pow = FuncList.get(i);
            result+= res[i]*fEMShapeFunction1D1Pow.calculateDerivaty(x);
        }
        result = derivavty.calculate(x, this);
        return result;
    }


}
